$(document).ready(function() {
	$('.no-pwd').hide();
});

function displayInfo(item) {
	$.ajax({
		url: "infouser",
		type: "post",
		data: {login:[item]},
		dataType: "json",
		success: function(user) {
			var pwd = user.hasPwd ? "Oui" : "Non";
			$("#info-user").html(user.nom + " " + user.prenom + " - Password : " + pwd);
			if(!user.hasPwd) {
				$('.pwd').hide(300);
				$('.no-pwd').show(300);
			}
		},
		error: function(e,xhr) {
			alert("Cet utilisateur n'existe pas.");
		}
	});
}

function removeInfo() {
	$("#info-user").html("");
	$('.pwd').show(300);
	$('.no-pwd').hide(300);
}

$(document).ready(function() {
	$('#switch').iphoneSwitch("off",
			function() {
		$('#suppr').attr('checked', true);
		Disabled('pwd');
		Disabled('pwd_verif');
	},
	function() {
		$('#suppr').attr('checked', false);
		Disabled('pwd');
		Disabled('pwd_verif');
	},
	{
		switch_on_container_path: '/css/jqueryui/iphone-switch/iphone_switch_container_on.png',
		switch_off_container_path: '/css/jqueryui/iphone-switch/iphone_switch_container_off.png',
		switch_path: '/css/jqueryui/iphone-switch/iphone_switch.png'
	});
});

function pwdOk(data) {
	if(data.length == 0) {
		$('#pwd-ok').html("");
	} else if(data.length > 5) {
		$('#pwd-ok').html("<img style='width:16 px; height: 16px' src='/css/main/images/icons/tick.png'/>");
		if(data == $('#pwd_verif').val()) {
			$('#pwd-verif-ok').html("<img style='width:16 px; height: 16px' src='/css/main/images/icons/tick.png'/>");
		} else if($('#pwd_verif').val().length > 0) {
			$('#pwd-verif-ok').html("<img style='width:16 px; height: 16px' src='/css/main/images/icons/cross.png'/>");
		}
	} else {
		$('#pwd-ok').html("<img style='width:16 px; height: 16px' src='/css/main/images/icons/cross.png'/>");
	}
}

function verifPwdOk(data) {
	if(data.length == 0) {
		$('#pwd-verif-ok').html("");
	} else if(data == $('#pwd').val()) {
		$('#pwd-verif-ok').html("<img style='width:16 px; height: 16px' src='/css/main/images/icons/tick.png'/>");
	} else {
		$('#pwd-verif-ok').html("<img style='width:16 px; height: 16px' src='/css/main/images/icons/cross.png'/>");
	}
}